#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList; 
Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L, int n)
{
	LNode *t = L;
	for(int i = 0; i < n; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t->next;
		t->next = p;
		t = p;
	}
	return OK;
}
void Union(LinkList &la, LinkList &lb) // 把la变成交集 
{
	/**************Begin*************/
	LNode *pa = la->next, *t = la;  
    la->next = NULL;    
	    
    while (pa) 
	{
        LNode *pb = lb->next;
        while (pb) 
		{
            if (pa->data == pb->data) 
			{
                
                LNode *q = new LNode;
                q->data = pa->data;
                q->next = NULL;
                t->next = q;
                t = q;
            }
            pb = pb->next;
        }
        pa = pa->next;
    }
	delete lb;
    
    /**************End**************/
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L1, L2;
	Init(L1);
	Init(L2);
	int n1, n2;
	cin >> n1 >> n2;
	Create(L1, n1);
	Create(L2, n2);
	Union(L1, L2);
	Show(L1);
	return 0;
}